<template>
  <div>
    <div style="display: flex">
      <a-button class="editable-add-btn" @click="showModal"> Add </a-button>
    </div>
    <a-modal v-model="visible" title="新增用户" @ok="handleOk">
      <a-form :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
        <a-form-item label="用户名">
          <a-input v-model="userName" />
        </a-form-item>
        <a-form-item label="密码">
          <a-input v-model="password" />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      formLayout: "horizontal",
      visible: false,
      userName: "",
      password: "",
    };
  },
  methods: {
    showModal() {
      this.visible = true;
    },
    handleOk(e) {
      const newUser = {
        userName: this.userName,
        password: this.password,
      };
      axios.post("http://localhost:8080/api/user/one", newUser).then(
        (response) => {
          console.log(response.data.msg);
          this.visible = false;
        },
        (error) => {
          console.log(error.message.msg);
        }
      );
    },
  },
};
</script>

<style scoped>
.editable-add-btn {
  margin-bottom: 8px;
}
</style>
